{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ad23c6d2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "os.environ[\"OPENAI_API_KEY\"] = \"sk-proj-1234567890\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4cdf841d-bc87-4138-96d6-f8b6b173ddd8",
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index.core.agent.workflow import FunctionAgent\n",
    "from llama_index.llms.openai import OpenAI"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6358bd48-627c-47d6-9761-376877195950",
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index.tools.azure_speech.base import AzureSpeechToolSpec\n",
    "from llama_index.tools.azure_translate.base import AzureTranslateToolSpec\n",
    "from llama_index.core.workflow import Context\n",
    "\n",
    "speech_tool = AzureSpeechToolSpec(speech_key=\"your-key\", region=\"eastus\")\n",
    "translate_tool = AzureTranslateToolSpec(api_key=\"your-key\", region=\"eastus\")\n",
    "\n",
    "agent = FunctionAgent(\n",
    "    tools=[*speech_tool.to_tool_list(), *translate_tool.to_tool_list()],\n",
    "    llm=OpenAI(model=\"gpt-4.1\"),\n",
    ")\n",
    "ctx = Context(agent)\n",
    "\n",
    "print(await agent.run('Say \"hello world\"', ctx=ctx))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cfd64436-ec97-4fa5-977a-0e520ccc7e0d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "('data/speech.wav', <http.client.HTTPMessage at 0x7f8cf3c84fa0>)"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# We use one of the Azure resources of an insurance call for the next example.\n",
    "# Use this cell to download the file, or put your own file in data/speech.wav\n",
    "import urllib.request\n",
    "\n",
    "urllib.request.urlretrieve(\n",
    "    \"https://speechstudiorawgithubscenarioscdn.azureedge.net/call-center/sampledata/Call1_separated_16k_health_insurance.wav\",\n",
    "    \"data/speech.wav\",\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "71c0244c-d9f3-4849-8571-50cee19f705b",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(await agent.run(\"transcribe and format conversation in data/speech.wav\", ctx=ctx))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5dc5d831-f08d-4d62-993a-f1b6e4070f7c",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(await agent.run(\"translate the conversation into spanish\", ctx=ctx))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
